package com.dhecp.project.business.service.impl;

import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.dhecp.common.config.Global;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.MessageUtils;
import com.dhecp.common.utils.RandomValueUtils;
import com.dhecp.common.utils.StringUtils;
import com.dhecp.common.utils.barcode.BarcodeUtil;
import com.dhecp.common.utils.pdf.FreeMarkerPdfUtil;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.business.domain.ProductBasis;
import com.dhecp.project.business.domain.ProductBasisCompete;
import com.dhecp.project.business.domain.ProductBasisComponent;
import com.dhecp.project.business.mapper.ProductBasisMapper;
import com.dhecp.project.business.service.ProductBasisService;
import com.dhecp.project.common.domain.DataBaseMessage;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * 基础商品库  业务实现层
 * @author DH-Xxj
 * @version 2022年7月13日
 */
@Service
public class ProductBasisServiceImpl implements ProductBasisService {

	@Autowired
	private ProductBasisMapper productBasisMapper;

	@Autowired
	private SysDictionaryForFieldService dictionaryForFieldService;

	/**
     * 查询基础商品库
	 * @param params
	 * @return List - ProductBasis
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductBasis> queryProductBasis(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
//        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "name asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		
		return productBasisMapper.findProductBasis(params);
	}

	/**
     * 查询基础商品子件
	 * @param params
	 * @return List - ProductBasisComponent
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductBasisComponent> queryProductBasisComponent(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
//        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "pcode,name asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		
		return productBasisMapper.findProductBasisComponent(params);
	}

	/**
     * 查询基础竞品库
	 * @param params
	 * @return List - ProductBasisCompete
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductBasisCompete> queryProductBasisCompete(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
//        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "pcode,asin asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		
		return productBasisMapper.findProductBasisCompete(params);
	}

	/**
	 * 通过guid查询单条基础商品库
	 * @param guid
	 * @return 实体 ProductBasis
	 * @author DH-Xxj
	 */
	@Override
	public ProductBasis queryProductBasisByGuid(String guid) {
		return productBasisMapper.findProductBasisByGuid(guid);
	}

	/**
	 * 通过code查询单条基础商品库
	 * @param code
	 * @return 实体 ProductBasis
	 * @author DH-Xxj
	 */
	@Override
	public ProductBasis queryProductBasisByCode(String code) {
		return productBasisMapper.findProductBasisByCode(code);
	}

	/**
	 * 通过guid查询单条基础商品子件
	 * @param guid
	 * @return 实体 ProductBasisComponent
	 * @author DH-Xxj
	 */
	@Override
	public ProductBasisComponent queryProductBasisComponentByGuid(String guid) {
		return productBasisMapper.findProductBasisComponentByGuid(guid);
	}

	/**
	 * 通过guid查询单条基础竞品库
	 * @param guid
	 * @return 实体 ProductBasisCompete
	 * @author DH-Xxj
	 */
	@Override
	public ProductBasisCompete queryProductBasisCompeteByGuid(String guid) {
		return productBasisMapper.findProductBasisCompeteByGuid(guid);
	}

	/**
	 * 通过pcode查询基础商品子件
     * @param pcode 必要参数：商品母件编码
     * @return List - ProductBasisComponent
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductBasisComponent> queryProductBasisComponentBypcode(String pcode) {
		return productBasisMapper.findProductBasisComponentBypcode(pcode);
	}

	/**
	*@Description: 通过pcode查询基础商品子件 (多条
	*@Param: [pcode]
	*@return: java.util.List<com.dhecp.project.business.domain.ProductBasisComponent>
	*@Author: hlf
	*@date: 2022-08-18 17:14
	*/
	@Override
	public List<ProductBasisComponent> queryProductBasisComponentBypcode2(Map<String, Object> params) throws Exception {
		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "pcode asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		return productBasisMapper.findInProductBasisComponentBypcode(params);
	}


	/**
	*@Description: 查询已选择的数据
	*@Param: [params]
	*@return: java.util.List<com.dhecp.project.system.domain.SysUserInfoSimple>
	*@Author: hlf
	*@date: 2022-08-18 17:14
	*/
	@Override
	public List<ProductBasis> queryProductBasisList(Map<String, Object> params) throws Exception {
		params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
		params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));		//常规查询条件SQL语句
		if(params.containsKey("selIdList")){
			params.put("selIdList",params.get("selIdList").toString().split(","));
		}
		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "code asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		return productBasisMapper.queryProductBasisList(params);
	}

	/**
	 * 通过pcode查询基础竞品库
     * @param pcode 必要参数：商品母件编码
     * @return List - ProductBasisCompete
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductBasisCompete> queryProductBasisCompeteBypcode(String pcode) {
		return productBasisMapper.findProductBasisCompeteBypcode(pcode);
	}

	/**
	 * 清理商品导入过渡表中遗留的数据
	 * @param params
	 * @return AjaxResult
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult cleanProductBasisImport(Map<String, Object> params) {
		params.put("sessionId", ShiroUtils.getSessionId());
		DataBaseMessage dataBaseMessage = productBasisMapper.cleanProductBasisImport(params);
		
		if ("0".equals(dataBaseMessage.getCode())){
			return AjaxResult.success(dataBaseMessage.getMsg());
		}else if ("301".equals(dataBaseMessage.getCode())){
			return AjaxResult.warn(dataBaseMessage.getMsg());
		}else if ("500".equals(dataBaseMessage.getCode())){
			return AjaxResult.error(dataBaseMessage.getMsg());
		}else{
			return AjaxResult.error("未知服务器错误，请重试。");
		}
	}

	/**
	 * 将本次导入的商品数据从商品导入过渡表中转入商品库正式表
	 * @param records 导入总记录数int类型
	 * @return AjaxResult
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult importToProductBasis(Map<String, Object> params) {
		params.put("sessionId", ShiroUtils.getSessionId());
		if (params.get("records") == null){
			params.put("records", 0);
		}
		DataBaseMessage dataBaseMessage = productBasisMapper.importToProductBasis(params);
		
		if ("0".equals(dataBaseMessage.getCode())){
			return AjaxResult.success(dataBaseMessage.getMsg());
		}else if ("301".equals(dataBaseMessage.getCode())){
			return AjaxResult.warn(dataBaseMessage.getMsg());
		}else if ("500".equals(dataBaseMessage.getCode())){
			return AjaxResult.error(dataBaseMessage.getMsg());
		}else{
			return AjaxResult.error("未知服务器错误，请重试。");
		}
	}

	/**
	 * 导入产品信息至产品信息过渡表
	 * @param productBasisItems 必要参数：基础商品库对应实体类（ProductBasis）的json格式字符串
	 * @return MessageModel
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult importProductBasis(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		
		List<ProductBasis> productBasisList = JSON.parseArray(params.get("productBasisItems").toString(), ProductBasis.class);
		if (productBasisList == null || productBasisList.size() == 0) {
			return AjaxResult.error("数据包格式有误，请检查！");
		}

		for (ProductBasis productBasis : productBasisList) {
			AjaxResult ajaxResult = checkedProductKey(productBasis);
			if (!"0".equals(ajaxResult.get("code").toString())){
				return ajaxResult;
			}
		}


		for (ProductBasis productBasis : productBasisList) {



			productBasis.setCreateUser(ShiroUtils.getUserId());
			productBasis.setCreateUserName(ShiroUtils.getUserName());
			productBasis.setCreateDept(ShiroUtils.getUserDeptPath());
			productBasis.setCreateDeptName(ShiroUtils.getUserDeptName());
			productBasis.setCreatePosition(ShiroUtils.getUserPositionNameDa());
			productBasis.setCreateTime(new Date());
			productBasis.setSessionId(ShiroUtils.getSessionId());
			
			productBasisMapper.importProductBasis(productBasis);
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 新增基础商品库
	 * @param productBasisItems 必要参数：基础商品库对应实体类（ProductBasis）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult insertProductBasis(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<ProductBasis> productBasisList = JSON.parseArray(params.get("productBasisItems").toString(), ProductBasis.class);
		if (productBasisList == null || productBasisList.size() == 0) {
			return AjaxResult.error("请添加需要保存的商品信息。");
		}

		for (ProductBasis productBasis : productBasisList) {
			productBasis.setCreateUser(ShiroUtils.getUserId());
			productBasis.setCreateUserName(ShiroUtils.getUserName());
			productBasis.setCreateDept(ShiroUtils.getUserDeptPath());
			productBasis.setCreateDeptName(ShiroUtils.getUserDeptName());
			productBasis.setCreatePosition(ShiroUtils.getUserPositionNameDa());
			productBasis.setCreateTime(new Date());
			productBasis.setUpdateUser(ShiroUtils.getUserId());
			productBasis.setUpdateTime(new Date());
			if (productBasis.getGuid() == null || "".equals(productBasis.getGuid())){
				productBasis.setGuid(RandomValueUtils.getGUID());
			}
			productBasisMapper.insertProductBasis(productBasis);
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 新增基础商品子件
	 * @param productBasisComponentItems 必要参数：基础商品子件对应实体类（ProductBasisComponent）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult insertProductBasisComponent(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<ProductBasisComponent> productBasisComponentList = JSON.parseArray(params.get("productBasisComponentItems").toString(), ProductBasisComponent.class);
		if (productBasisComponentList == null || productBasisComponentList.size() == 0) {
			return AjaxResult.error("请添加需要保存的商品子件信息。");
		}

		for (ProductBasisComponent productBasisComponent : productBasisComponentList) {
			if (productBasisComponent.getPcode() == null || "".equals(productBasisComponent.getPcode())){
				return AjaxResult.error("商品子件中母件编码（pcode）不能为空！");
			}
			productBasisComponent.setCreateUser(ShiroUtils.getUserId());
			productBasisComponent.setCreateTime(new Date());
			productBasisComponent.setUpdateUser(ShiroUtils.getUserId());
			productBasisComponent.setUpdateTime(new Date());
//			if (productBasisComponent.getGuid() == null || "".equals(productBasisComponent.getGuid())){
//				productBasisComponent.setGuid(RandomValueUtils.getGUID());
//			}
			ProductBasisComponent isProduct = productBasisMapper.findProductBasisComponentByCode(productBasisComponent.getCode());//判断子件是否存在
			if (isProduct != null){
				productBasisMapper.deleteProductBasisComponentByCode(isProduct.getCode());
			}

			productBasisMapper.insertProductBasisComponent(productBasisComponent);
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 新增基础竞品库
	 * @param productBasisCompeteItems 必要参数：基础竞品库对应实体类（ProductBasisCompete）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult insertProductBasisCompete(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<ProductBasisCompete> productBasisCompeteList = JSON.parseArray(params.get("productBasisCompeteItems").toString(), ProductBasisCompete.class);
		if (productBasisCompeteList == null || productBasisCompeteList.size() == 0) {
			return AjaxResult.error("请添加需要保存的商品竞品信息。");
		}

		for (ProductBasisCompete productBasisCompete : productBasisCompeteList) {
			if (productBasisCompete.getPcode() == null || "".equals(productBasisCompete.getPcode())){
				return AjaxResult.error("商品竞品中母件编码（pcode）不能为空！");
			}
			productBasisCompete.setCreateUser(ShiroUtils.getUserId());
			productBasisCompete.setCreateTime(new Date());
			productBasisCompete.setUpdateUser(ShiroUtils.getUserId());
			productBasisCompete.setUpdateTime(new Date());
			if (productBasisCompete.getGuid() == null || "".equals(productBasisCompete.getGuid())){
				productBasisCompete.setGuid(RandomValueUtils.getGUID());
			}
			productBasisMapper.insertProductBasisCompete(productBasisCompete);
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 保存基础商品子件（先删除后新增）
	 * @param pcode 必要参数：基础商品库中的商品编码（code）
	 * @param productBasisComponentItems 必要参数：基础商品子件对应实体类（ProductBasisComponent）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult saveProductBasisComponent(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)){
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		if (params.get("pcode") == null || params.get("pcode") ==""){
			return AjaxResult.error("请提供必要参数（pcode）【基础商品库中的商品编码（code）】。");
		}
		productBasisMapper.deleteProductBasisComponentBypcode(params.get("pcode").toString());
		List<ProductBasisComponent> productBasisComponentList = JSON.parseArray(params.get("productBasisComponentItems").toString(), ProductBasisComponent.class);
		if (productBasisComponentList != null && productBasisComponentList.size() > 0) {
			for (ProductBasisComponent productBasisComponent : productBasisComponentList) {
				if (productBasisComponent.getPcode() == null || "".equals(productBasisComponent.getPcode())){
					return AjaxResult.error("商品子件中母件编码（pcode）不能为空！");
				}
				productBasisComponent.setCreateUser(ShiroUtils.getUserId());
				productBasisComponent.setCreateTime(new Date());
				productBasisComponent.setUpdateUser(ShiroUtils.getUserId());
				productBasisComponent.setUpdateTime(new Date());
//				if (productBasisComponent.getGuid() == null || "".equals(productBasisComponent.getGuid())){
//					productBasisComponent.setGuid(RandomValueUtils.getGUID());
//				}
				productBasisMapper.insertProductBasisComponent(productBasisComponent);
			}
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 保存基础竞品库（先删除后新增）
	 * @param pcode 必要参数：基础商品库中的商品编码（code）
	 * @param productBasisCompeteItems 必要参数：基础竞品库对应实体类（ProductBasisCompete）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult saveProductBasisCompete(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)){
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		if (params.get("pcode") == null || params.get("pcode") ==""){
			return AjaxResult.error("请提供必要参数（pcode）【基础商品库中的商品编码（code）】。");
		}
		productBasisMapper.deleteProductBasisCompeteBypcode(params.get("pcode").toString());
		List<ProductBasisCompete> productBasisCompeteList = JSON.parseArray(params.get("productBasisCompeteItems").toString(), ProductBasisCompete.class);
		if (productBasisCompeteList != null && productBasisCompeteList.size() > 0) {
			for (ProductBasisCompete productBasisCompete : productBasisCompeteList) {
				if (productBasisCompete.getPcode() == null || "".equals(productBasisCompete.getPcode())){
					return AjaxResult.error("商品竞品中母件编码（pcode）不能为空！");
				}
				productBasisCompete.setCreateUser(ShiroUtils.getUserId());
				productBasisCompete.setCreateTime(new Date());
				productBasisCompete.setUpdateUser(ShiroUtils.getUserId());
				productBasisCompete.setUpdateTime(new Date());
				if (productBasisCompete.getGuid() == null || "".equals(productBasisCompete.getGuid())){
					productBasisCompete.setGuid(RandomValueUtils.getGUID());
				}
				productBasisMapper.insertProductBasisCompete(productBasisCompete);
			}
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 修改基础商品库
	 * @param productBasisItems 必要参数：基础商品库对应实体类（ProductBasis）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult updateProductBasis(Map<String, Object> params) {
		List<ProductBasis> productBasisList = JSON.parseArray(params.get("productBasisItems").toString(), ProductBasis.class);
		if (productBasisList == null || productBasisList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }
		
		for (ProductBasis productBasis : productBasisList) {
			productBasis.setUpdateUser(ShiroUtils.getUserId());
			productBasis.setUpdateTime(new Date());			
			productBasisMapper.updateProductBasis(productBasis);
		}
		return AjaxResult.success("操作成功！");
	}

	/**
	 * 修改基础商品子件
	 * @param productBasisComponentItems 必要参数：基础商品子件对应实体类（ProductBasisComponent）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult updateProductBasisComponent(Map<String, Object> params) {
		List<ProductBasisComponent> productBasisComponentList = JSON.parseArray(params.get("productBasisComponentItems").toString(), ProductBasisComponent.class);
		if (productBasisComponentList == null || productBasisComponentList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }
		
		for (ProductBasisComponent productBasisComponent : productBasisComponentList) {
			if (productBasisComponent.getPcode() == null || "".equals(productBasisComponent.getPcode())){
				return AjaxResult.error("商品子件中母件编码（pcode）不能为空！");
			}
			productBasisComponent.setUpdateUser(ShiroUtils.getUserId());
			productBasisComponent.setUpdateTime(new Date());			
			productBasisMapper.updateProductBasisComponent(productBasisComponent);
		}
		return AjaxResult.success("操作成功！");
	}

	/**
	 * 修改基础竞品库
	 * @param productBasisCompeteItems 必要参数：基础竞品库对应实体类（ProductBasisCompete）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult updateProductBasisCompete(Map<String, Object> params) {
		List<ProductBasisCompete> productBasisCompeteList = JSON.parseArray(params.get("productBasisCompeteItems").toString(), ProductBasisCompete.class);
		if (productBasisCompeteList == null || productBasisCompeteList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }
		
		for (ProductBasisCompete productBasisCompete : productBasisCompeteList) {
			if (productBasisCompete.getPcode() == null || "".equals(productBasisCompete.getPcode())){
				return AjaxResult.error("商品竞品中母件编码（pcode）不能为空！");
			}
			productBasisCompete.setUpdateUser(ShiroUtils.getUserId());
			productBasisCompete.setUpdateTime(new Date());			
			productBasisMapper.updateProductBasisCompete(productBasisCompete);
		}
		return AjaxResult.success("操作成功！");
	}

	/**
	 * 通过Guid删除基础商品库
	 * @param productBasisItems 必要参数：基础商品库对应实体类（ProductBasis）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult deleteProductBasisByGuid(Map<String, Object> params) {
		List<ProductBasis> productBasisList = JSON.parseArray(params.get("productBasisItems").toString(), ProductBasis.class);
		if (productBasisList == null || productBasisList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }

		for (ProductBasis productBasis : productBasisList) {
			productBasisMapper.deleteProductBasisByGuid(productBasis.getGuid() == null ? "noguid" : productBasis.getGuid());
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 通过Guid删除基础商品库（完整删除，包含子件和竞品）
	 * @param productBasisItems 必要参数：基础商品库对应实体类（ProductBasis）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult deleteProductBasisCompleteByGuid(Map<String, Object> params) {
		List<ProductBasis> productBasisList = JSON.parseArray(params.get("productBasisItems").toString(), ProductBasis.class);
		String pcode = ""; //商品母件编码
		if (productBasisList == null || productBasisList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }

		for (ProductBasis productBasis : productBasisList) {
			if (productBasis.getCode() != null){
				pcode = productBasis.getCode().toString();
				productBasisMapper.deleteProductBasisComponentBypcode(pcode);
				productBasisMapper.deleteProductBasisCompeteBypcode(pcode);
			}
			productBasisMapper.deleteProductBasisByGuid(productBasis.getGuid() == null ? "noguid" : productBasis.getGuid());
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 通过Guid删除基础商品子件
	 * @param productBasisComponentItems 必要参数：基础商品子件对应实体类（ProductBasisComponent）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult deleteProductBasisComponentByGuid(Map<String, Object> params) {
		List<ProductBasisComponent> productBasisComponentList = JSON.parseArray(params.get("productBasisComponentItems").toString(), ProductBasisComponent.class);
		if (productBasisComponentList == null || productBasisComponentList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }

		for (ProductBasisComponent productBasisComponent : productBasisComponentList) {
//			productBasisMapper.deleteProductBasisComponentByGuid(productBasisComponent.getGuid() == null ? "noguid" : productBasisComponent.getGuid());
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 通过Guid删除基础竞品库
	 * @param productBasisCompeteItems 必要参数：基础竞品库对应实体类（ProductBasisCompete）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult deleteProductBasisCompeteByGuid(Map<String, Object> params) {
		List<ProductBasisCompete> productBasisCompeteList = JSON.parseArray(params.get("productBasisCompeteItems").toString(), ProductBasisCompete.class);
		if (productBasisCompeteList == null || productBasisCompeteList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }

		for (ProductBasisCompete productBasisCompete : productBasisCompeteList) {
			productBasisMapper.deleteProductBasisCompeteByGuid(productBasisCompete.getGuid() == null ? "noguid" : productBasisCompete.getGuid());
		}
		return AjaxResult.success("操作成功");
	}
	
	/**
	 * 从基础商品库调入选品
	 * @param params
	 * @return List - ProductBasis
	 * @throws Exception
	 * @author DH-Xxj
	 */
//	@Override
	public List<ProductBasis> queryCallProductXP(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
//        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "name asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		
		return productBasisMapper.callProductXP(params);
	}

	/**
	 * 验证商品主键是否为空
	 * @param productBasis
	 * @return
	 * @author DH-Xxj
	 */
	private AjaxResult checkedProductKey(ProductBasis productBasis){
		if (StringUtils.isEmpty(productBasis.getCode()) || StringUtils.isEmpty(productBasis.getName())){
			return AjaxResult.error("【商品编码、商品名称】不能为空，请删除或修改存在空值的产品信息。");
		}
		return AjaxResult.success();
	}



	/**
	 * 修改状态
	 *
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult updateState(Map<String, Object> params) {
		ProductBasis item = JSON.parseObject(params.get("infoItem").toString(), ProductBasis.class);
		productBasisMapper.updateProductBasisState(item);
		return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
	}

	@Override
	public String createGoodsPdf(String productCode, String productNameEn, Integer num) {
		
		productNameEn = productNameEn == null ? "" : productNameEn;
		
		// 生成条形码图片
		String fileDir = Global.getProfile() + "/barcodeImg";
		File tempDir = new File(fileDir + "/");
		if (!tempDir.exists()) {
			tempDir.mkdirs();
		}
		
		String fileName = productCode + ".png";
		BufferedImage barCodeImage = BarcodeUtil.createImg(productCode, 500, 200);
		String imgFile = BarcodeUtil.createBarcodeImgFile(barCodeImage, fileDir, fileName);
		System.out.println("imgFile---" + imgFile);
		
		// 生成PDF
		Map<String, Object> paramMap = new HashMap<String, Object>();
		//这里是给具体的某些字段赋值
		paramMap.put("productCode", productCode);
		paramMap.put("productNameEn", productNameEn);
		paramMap.put("imgFile", "file:" + imgFile);
		paramMap.put("num", num);
		paramMap.put("totalPage", (num + 26) / 27);
		//调用具体的实现方法
    	String templatePath = Global.getProfile() + "/pdfmuban/";
		String templateName = "goods.ftl";
		String desDir = Global.getProfile() + "/goodspdf/";
		String tempHtmlName = productCode + ".html";
		String desPdfName = productCode + ".pdf";
		String fontDir = templatePath;
		FreeMarkerPdfUtil.createPdf(templatePath, templateName, desDir, tempHtmlName, desPdfName, fontDir, paramMap);
		return desDir + desPdfName;
		
	}
	
}
